package com.yanqu.road.server.cmd.banquet.party;

import com.yanqu.road.pb.banquet.BanquetProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.relatives.RelativesModule;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;
import io.netty.channel.ChannelHandlerContext;

import java.util.List;

@Cmd(code = GameProtocol.S_CROSS_PARTY_SYNC, desc = "")
public class CrossPartySyncCmd implements Command {
    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        BanquetProto.BanquetFeastSync msg = BanquetProto.BanquetFeastSync.parseFrom(packet.getBytes());
        List<BanquetProto.BanquetTemp> banquetTemps = msg.getBanquetDataListList();
        for (GamePlayer player : GamePlayerMgr.getAllOnlinePlayer()) {
            BanquetProto.BanquetFeastSync.Builder syncMsg = BanquetProto.BanquetFeastSync.newBuilder();
            for (BanquetProto.BanquetTemp temp : banquetTemps) {
                BanquetProto.BanquetTemp.Builder builder = temp.toBuilder();
                builder.setSelfJoin(temp.getJoinListList().contains(player.getUserId()));
                builder.setIsKinship(player.getModule(RelativesModule.class).getRelativesInfo(temp.getUserId()) != null);
                syncMsg.addBanquetDataList(builder);
            }
            player.sendPacket(Protocol.U_BANQUET_FEAST_SYNC, syncMsg);
        }

    }
}
